package com.gl.glbooks.view.components.customPanel
{
	import flash.events.Event;
	
	import mx.controls.Alert;
	import mx.controls.Image;
	
	import spark.components.Button;
	import spark.components.Panel;

	[Event(name="buttonClicked", type="flash.events.Event")]
	public class ButtonBackPanel extends Panel
	{
		public var sectionTarget:String;
		
		//Imagen
		[Embed(source="assets/back.png")]
		[Bindable]
		public var image:Class;

		protected var backButton:Image;
		
		protected function doCreateForm(event:Event):void{
			event = new Event("buttonClicked");
			dispatchEvent(event);
		}
		
		
		protected override function createChildren():void{
			
			super.createChildren();
			
			//instaciar boton
			backButton = new Image();
			backButton.source = image;
			backButton.buttonMode = true;
			backButton.height=25;
			backButton.height=25;

			//event listener boton
			backButton.addEventListener("click", doCreateForm);
			backButton.visible = true;
			//agregar boton
			this.addElement(backButton);
		}
		
		
		//posicion del boton
		protected override function updateDisplayList(unscaledWidth:Number,
													  unscaledHeight:Number):void{
			
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			
			var margin:int = 4;
			
			backButton.setActualSize(50 + margin, 16 + margin);
			
			var pixelsRight:int = -5;
			var pixelsTop:int = -28;

			var buttonWidth:int = backButton.width;

			var x:Number = unscaledWidth - buttonWidth - pixelsRight;
			var y:Number = pixelsTop;

			backButton.move(x, y);
		}
		
		public function ButtonBackPanel()
		{
			super();
		}
	}
}